package org.hdax.controller;

import org.hdax.entity.EasybuyUser;
import org.hdax.service.EasybuyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    private EasybuyUserService userService;
    @Value("${server.port}")
    private Integer port;

    @PostMapping("/login")
    public EasybuyUser login(@RequestBody Map<String,String> params) throws Exception{
        EasybuyUser user = userService.findByUserNameOrMobile(params.get("name"));
        if (user != null){
            if (params.get("pwd").equals(user.getPassword())){
                return user;
            }
        }
        return null;
    }

    @GetMapping("/{id}")
    public EasybuyUser findById(@PathVariable Integer id){
        System.out.println(port);
        return userService.findById(id);
    }
}
